FROM python:3.10-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

COPY . .

# Apply database migrations
RUN python manage.py migrate

# Set environment variables for Django superuser
ENV DJANGO_SUPERUSER_USERNAME=admin
ENV DJANGO_SUPERUSER_PASSWORD=123456
ENV DJANGO_SUPERUSER_EMAIL=admin@example.com

# Create Django superuser non-interactively
RUN python manage.py createsuperuser --noinput

# REMOVE this line:
# RUN python manage.py collectstatic --noinput

# Keep the CMD or ENTRYPOINT as is, it will be overridden by docker-compose command
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "application.wsgi:application"]